import axios from "axios";

import { getCookie } from "./auth.js"
import router from "@/router"
let service = axios.create({
    baseURL: "/api",
    timeout: 5000
})


// 拦截请求--给请求头中添加token
service.interceptors.request.use(config => {
    let token = getCookie("token")
    if (token) {
        config.headers["token"] = token
    }
    return config
})

// 拦截响应
service.interceptors.response.use(response => {
    console.log(response);
    let status = response.data.status
    switch (status) {
        case 401:
            router.push("/admin/login")
            break;
    }
    return response
})


export default service